package leetcode;

import java.util.*;

public class LC100 {


    public static List<List<String>> groupAnagrams(String[] strs) {

        HashMap<String,ArrayList<String>> hashMap = new HashMap<>();
        for (int i = 0; i < strs.length; i++) {
            char[] chars = strs[i].toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            ArrayList<String> list = hashMap.getOrDefault(key,new ArrayList<>());
            list.add(strs[i]);
            hashMap.put(key,list);
        }
        return new ArrayList<List<String>>(hashMap.values());
    }

    public static void main(String[] args) {
        List<List<String>> ans = groupAnagrams(new String[] {
                "eat", "tea", "tan", "ate", "nat", "bat"
        });
        System.out.println(ans);
    }
}
